<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/js/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/common.css" media="all">
    <link rel="stylesheet" href="../viewstyle/css/publicform.css">
    <script src="/js/layui/layui.js"></script>
    <script src="../viewstyle/config/config2.js"></script>
</head>

<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div style="text-align: center;">
                <div class="layui-inline">
                    <input class="layui-input" name="id" id="leibie" placeholder="站点名称或站点编号" autocomplete="off">
                </div>

                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-admin" id="btnsearch" lay-submit
                            lay-filter="LAY-user-back-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>搜索
                    </button>
                </div>
            </div>
        </div>
        <div class="layui-card-body">
            <table class="layui-table" id="table" lay-filter="t"></table>
        </div>
    </div>
</div>

</body>
<script type="text/html" id="tb">
    <div class="layui-container">
        <span class="">授权列表</span>
    </div>
</script>

<script type="text/html" id="sh">
    <button id="shouquan" value="授权" class="layui-btn layui-btn-sm" lay-event="shouquan">
        {{#if(d.copyrighttype==null || d.copyrighttype=='' ){}}
        授权
        {{# }else{}}
        取消授权
        {{# }}}
    </button>
</script>
</body>
<script>
    layui.use(['laydate', 'form', 'table', 'laypage'], function () {
        var $ = layui.$;
        var form = layui.form;
        var table = layui.table;
        var laypage = layui.laypage;
        var data = layui.data("banquan").getdata;
        var token = layui.data("local_store").token;
        var copyrightid = data.copyright_id;
        table.render({
            elem: "#table",
            url: "/admin/station/selcopyrightstation?copyrightid=" + data.copyrightid + "&token=" + token,
            id: "t",
            toolbar: '#tb',
            cols: [
                [{
                    title: "站点编号",
                    field: "station_bh",
                    width: "12%",
                    align: "center"
                },
                    {
                        title: "站点名称",
                        field: "station_name",
                        width: "12%",
                        align: "center"
                    }, {
                    title: "区域",
                    field: "station_quyu",
                    width: "12%",
                    align: "center"
                }, {
                    title: "类型",
                    field: "station_type_name",
                    width: "12%",
                    align: "center"
                }, {
                    title: "联系电话",
                    field: "station_phone",
                    width: "12%",
                    align: "center"
                },
                    {
                        title: "密码",
                        field: "station_password",
                        width: "12%",
                        align: "center"
                    },
                    {
                        title: "已授权",
                        field: "copyrighttype",
                        width: "14%",
                        templet: function (d) {
                            if (d.copyrighttype != null && d.copyrighttype != '') {
                                return `<input type="button" id="see" value="查看${d.copyrighttype}授权时间" class="layui-btn layui-btn-xs layui-btn-primary"
           lay-event="see"/>`
                            } else {
                                return ''
                            }
                        },
                        align: "center",
                    },
                    {
                        title: "stationid",
                        field: "station_id",
                        align: "center",
                        hide: true
                    },
                    {
                        title: "copyright_station_id",
                        field: "copyright_station_id",
                        align: "center",
                        hide: true
                    },
                    {
                        title: "操作",
                        align: "center",
                        toolbar: "#sh",
                        fixed: "right"
                    },
                ]
            ],
            page: true,
            limit:40
        });
        //  右侧按钮的的监听事件
        table.on("tool(t)", function (obj) {
            var getdata = obj.data; //获得当前行数据
            var layEvent = obj.event;
            var tr = obj.tr;
            layui.data('banquan_stationId', {
                key: 'getdata',
                value: getdata
            });
            switch (layEvent) {
                case"shouquan":
                    if (tr.find("button:last").html().trim() == "授权") {
                        layer.open(
                            {
                                title: "授权",
                                content: 'SetTime.html',
                                type: 2,
                                area: ['100%', '100%'],
                                end: function () {
                                    $(".layui-laypage-btn").click();
                                }
                            }
                        );
                    } else {
                        var close = layer.confirm("确定取消授权吗？", {
                            title: "提示",
                            btn: ["确定", "取消"],
                            btn1: function () {
                                $.ajax({
                                    type: "post",
                                    url: "/admin/copyrightstation/canleShouquan",
                                    data: {
                                        copyright_station_id: getdata.copyright_station_id,
                                    },
                                    success: function (res) {
                                        if (res.code == 200) {
                                            tr.find("td:eq(6)").html(" ");
                                            tr.find("button:last").html("授权");
                                            layer.msg("取消授权成功", {
                                                icon: 1,
                                                time: 1000
                                            });
                                            layer.close(close);
                                            return;
                                        }
                                        layer.msg(res.data, {
                                            icon: 2
                                        })
                                    },
                                    error: function () {
                                        layer.msg('网络原因取消授权成功', {
                                            icon: 2
                                        })
                                    }
                                })
                            }
                        })
                    }
                    break;
                case "see":
                    layer.open(
                        {
                            title: "授权时间",
                            content: 'SeeTime.html',
                            type: 2,
                            area: ['40%', '60%'],
                        }
                    );
                    break;
            }
        });
        $("#btnsearch").click(function () {
            table.reload('t', {
                where: {
                    search: $("#leibie").val()
                },
                page: {
                    curr: 1
                }
            })
        })
        $(window).keypress(function (event) {
            if (event.which === 13) {
                $('#btnsearch').click();
            }
        })
    });
</script>

</html>
